package lexis

import scala.util.matching.Regex
import utils.data.CEnum

case class CLexemeType(name:String, pattern:Regex, value:Option[String] = None)

object CLexemeType extends Iterable[CLexemeType]
{
    val LEFT_BRACKET = CLexemeType("LEFT_BRACKETS", """^\{""".r)
    val RIGHT_BRACKET = CLexemeType("RIGHT_BRACKETS", """^\}""".r)
    val LEFT_PARENTHESIS = CLexemeType("LEFT_PARENTHESIS", """^\(""".r)
    val RIGHT_PARENTHESIS = CLexemeType("RIGHT_PARENTHESIS", """^\)""".r)
    val COLON = CLexemeType("COLON", """^\:""".r)
    val COLON_ARROW = CLexemeType("LEFT_ARROW", """^\:\>""".r)
    val COMMA = CLexemeType("COMMA", """^\,""".r)
    val SEMICOLON = CLexemeType("SEMICOLON", """^\;""".r)
    val AT = CLexemeType("AT", """^\@""".r)
    val EQ = CLexemeType("EQ", """^\=\=""".r)
    val NEQ = CLexemeType("NEQ", """^\!\=""".r)
    val GTE = CLexemeType("GTE", """^\>\=""".r)
    val GT = CLexemeType("GT", """^\>""".r)
    val LTE = CLexemeType("LTE", """^\<\=""".r)
    val LT = CLexemeType("LT", """^\<""".r)
    val AND = CLexemeType("AND", """^\&\&""".r)
    val OR = CLexemeType("OR", """^\|\|""".r)
    val NOT = CLexemeType("NOT", """^\!""".r)
    val ADD = CLexemeType("ADD", """^\+""".r)
    val SUB = CLexemeType("SUB", """^\-""".r)
    val MUL = CLexemeType("MUL", """^\*""".r)
    val DIV = CLexemeType("DIV", """^\/""".r)
    val IF = CLexemeType("IF", """^[a-zA-Z]+\w*""".r, Some("if"))
    val ELSE = CLexemeType("ELSE", """^[a-zA-Z]+\w*""".r, Some("else"))
    val WHILE = CLexemeType("WHILE", """^[a-zA-Z]+\w*""".r, Some("while"))
    val ASSIGN = CLexemeType("ASSIGN", """^\=""".r)
    val NULL = CLexemeType("NULL", """^[a-zA-Z]+\w*""".r, Some("null"))
    val FALSE = CLexemeType("FALSE", """^[a-zA-Z]+\w*""".r, Some("false"))
    val TRUE = CLexemeType("TRUE", """^[a-zA-Z]+\w*""".r, Some("true"))
    val NUMBER = CLexemeType("NUMBER", """^(\d+)(\.?)(\d*)""".r)
    val IDENTIFIER = CLexemeType("IDENTIFIER", """^[a-zA-Z]+\w*""".r)
    val UNDERSCORE = CLexemeType("UNDERSCORE", """^\_""".r)
    val SPACE = CLexemeType("SPACE", """^\x20""".r)
    val NEW_LINE = CLexemeType("NEW_LINE", """^\n""".r)
    val TERMINATOR = CLexemeType("TERMINATOR", """^\`""".r)

    override def iterator = LEXEMES.iterator

    private val LEXEMES:Seq[CLexemeType] = CEnum(classOf[CLexemeType], this)
}
